package com.example.day06;

import java.util.Scanner;

/**
 * @author Lenovo
 */
public class Demo10 {
    public static void main(String[] args) {
        int[] arr = {9,28,37,46,50};
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要查找的数据：");
        int num = sc.nextInt();
//        int index =-1;
//        for (int i = 0; i < arr.length; i++) {
//            if(arr[i]==num){
//                index=i;
//                break;
//            }
//        }
        int index = getIndex(arr,num);
        System.out.println("num="+num+"的索引是："+index);
    }
    public  static int getIndex(int[] arr,int num){
        int index =-1;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]==num){
                index=i;
                break;
            }
        }
        return index;
    }
}
